<template>
  <page-layout>
    <div class="card-header">志愿者管理</div>
    <el-card class="box-card">
      <el-card class="box-card">
        <el-form ref="searchVolunteerCondition" :model="searchVolunteerCondition" label-width="80px" inline>
          <el-form-item label="标题">
            <el-input v-model="searchVolunteerCondition.title" style="width: 300px;"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="refresh(1)">查询</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <div class="flex-row">
        <div class="flex-item">
          <el-card class="box-card">
            <el-table
              :data="volunteerList.content" border stripe
              style="width: 100%">
              <el-table-column
                prop="id"
                label="编号"
                width="55">
              </el-table-column>
              <el-table-column prop="name" label="姓名" width="210">
              </el-table-column>
              <el-table-column prop="sex" label="性别" ></el-table-column>
              <el-table-column
                prop="intent"
                label="工作意向" width="120">
              </el-table-column>
              <el-table-column
                prop="phone"
                label="联系电话" width="120">
              </el-table-column> <el-table-column
                prop="birth"
                label="出生日期" width="120">
              </el-table-column>
              <el-table-column prop="message" label="留言" >
              </el-table-column>
              <el-table-column label="操作" width="180">
                <template slot-scope="scope">
                  <el-button size="mini" type="text" @click="deleteVolunteer(scope.row)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="mt10">
              <el-pagination
                background
                layout="prev, pager, next"
                :total="volunteerList.totalElements"
                :page-size="volunteerList.size"
                :current-page.sync="currentVolunteerPage" @current-change="getPageChange">
              </el-pagination>
            </div>
          </el-card>
        </div>
      </div>
    </el-card>
  </page-layout>
</template>
<script>
import PageLayout from "@/components/page-layout";
import { mapGetters } from "vuex";
export default {
  created() {
    this.refresh();
  },
  mounted() {},
  data() {
    return {
      currentVolunteerPage: 1
    };
  },
  computed: {
    ...mapGetters({
      volunteerList: "volunteerList",
      searchVolunteerCondition: "searchVolunteerCondition"
    })
  },
  methods: {
    getPageChange(val) {
      var tem = Object.assign(
        { pageIndex: val - 1 },
        this.searchVolunteerCondition
      );
      this.$store.dispatch("getVolunteerPageS", tem).then(ret => {});
    },
    refresh() {
      this.getPageChange(1);
    },
    deleteVolunteer(row) {
      this.$confirm("确认删除当前志愿者?", "提示", {})
        .then(() => {
          this.$store.dispatch("deleteVolunteerS", { id: row.id }).then(ret => {
            this.refresh();
            this.$notify({
              title: "删除成功",
              type: "success"
            });
          });
        })
        .catch(() => {});
    }
  },
  components: {
    PageLayout
  }
};
</script>
<style>
</style>
